package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseTeacherApi;
import com.xuecheng.api.content.model.dto.CourseTeacherDTO;
import com.xuecheng.content.service.CourseTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CourseTeacherController implements CourseTeacherApi {

    @Autowired
    private CourseTeacherService courseTeacherService;


    /**
     * 根据课程id获取教师信息集合
     *
     * @param courseBaseId 课程id
     * @return 教师信息集合
     */
    @GetMapping("courseTeacher/list/{courseBaseId}")
    public List<CourseTeacherDTO> queryTeacherList(@PathVariable Long courseBaseId) {
        List<CourseTeacherDTO> resultList = this.courseTeacherService.queryTeacherList(courseBaseId);
        return resultList;
    }

    /**
     * 创建或修改教师信息
     *
     * @param dto 教师信息
     * @return 更新之后的教师信息
     */
    @PostMapping("courseTeacher")
    public CourseTeacherDTO createOrModifyTeacher(@RequestBody CourseTeacherDTO dto) {
        CourseTeacherDTO result = this.courseTeacherService.createOrModifyTeacher(dto);
        return result;
    }

    /**
     * 根据课程id和教师信息id删除教师信息
     *
     * @param courseBaseId    课程id
     * @param courseTeacherId 教师信息id
     */
    @DeleteMapping("courseTeacher/course/{courseBaseId}/{courseTeacherId}")
    public void deleteTeacher(@PathVariable Long courseBaseId, @PathVariable Long courseTeacherId) {
        this.courseTeacherService.deleteTeacher(courseBaseId, courseTeacherId);
    }
}
